#include "mylabel.h"
#include "QDebug"
#include "QMouseEvent"
mylabel::mylabel(QWidget *parent) : QLabel(parent)
{

}
void mylabel::enterEvent(QEvent *event){
    qDebug()<<"鼠标进来了";
}
void mylabel::leaveEvent(QEvent *){
    qDebug()<<"鼠标出去了";
}

void mylabel::mousePressEvent(QMouseEvent *ev){
    if(ev->button()&Qt::LeftButton){
        QString str=QString("鼠标被按下了 x=%1 y=%2 globalx=%3 globaly=%4").arg(ev->x()).arg(ev->y()).arg(ev->globalX()).arg(ev->globalY());
        qDebug()<<str;
    }

}
void mylabel::mouseMoveEvent(QMouseEvent *ev){
    if(ev->buttons()==Qt::LeftButton){
        QString str=QString("鼠标被移动了 x=%1 y=%2").arg(ev->x()).arg(ev->y());
        qDebug()<<str;
    }

}
void mylabel::mouseReleaseEvent(QMouseEvent *ev){
    if(ev->button()==Qt::LeftButton){
        QString str=QString("鼠标被松开了 x=%1 y=%2").arg(ev->x()).arg(ev->y());
        qDebug()<<str;
    }

}

bool mylabel::event(QEvent *e) {
    //分发器判断鼠标按下
    if(e->type()==QEvent::MouseButtonPress){
        QMouseEvent *ev=static_cast<QMouseEvent*>(e);
        QString str=QString("event中鼠标被松开了 x=%1 y=%2").arg(ev->x()).arg(ev->y());
        qDebug()<<str;
        //返回ture，说明给用户处理
        return true;
    }
    return QLabel::event(e);
}

mylabel::~mylabel(){

}
